package planeGame;

import java.awt.*;

/**
 * 炮弹类
 */
public class Shell extends GameObject{
    double degree;//弧度

    public Shell(){
        x=200;
        y=200;
        width=10;
        height=10;
        speed=4;
        degree=Math.random()*Math.PI*2;
    }

    public void draw(Graphics g){
        Color c=g.getColor();
        g.setColor(Color.YELLOW);
        //填充一个炮弹
        g.fillOval((int)x,(int)y,width,height);
        //炮弹沿任意夹角去飞
        x+=speed*Math.cos(degree);
        y+=speed*Math.sin(degree);
        //边界处理
        if(x<=0||x>=Constant.GAME_WIDTH-width){
            degree = Math.PI-degree;
        }
        if(y<=30||y>=Constant.GAME_HEIGHT-height){
            degree = Math.PI-degree;
        }

        g.setColor(c);
    }
}
